package org.dftproject.genesis.data.genealogy.impl;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.dftproject.genesis.data.genealogy.IEvent;
import org.dftproject.genesis.data.genealogy.IRole;
import org.dftproject.genesis.data.impl.EntityImpl;

public class EventImpl extends EntityImpl implements IEvent {
	
	private final Set<IRole> roles = new HashSet<IRole>();

	public Set<IRole> getRoles() {
		return Collections.unmodifiableSet(roles);
	}
	
	public Set<IRole> getRoles(String type) {		
		Set<IRole> matchingRoles = new HashSet<IRole>();
		
		for (IRole role : roles) {
			if (type.equals(role.getType()))
				matchingRoles.add(role);
		}
		
		return Collections.unmodifiableSet(matchingRoles);
	}
	
	public Set<IRole> getRoles(String[] types) {		
		Set<IRole> matchingRoles = new HashSet<IRole>();
		
		for (IRole role : roles) {
			for (String type : types) {
				if(type.equals(role.getType())) {
					matchingRoles.add(role);
					break;
				}
			}
		}
		
		return Collections.unmodifiableSet(matchingRoles);
	}

	public void addRole(IRole role) {
		roles.add(role);
	}
	
	@Override
	public String toString() {
		return "Event(roles=" + roles.toString() + ")";
	}

}
